package org.apache.struts.register.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts.register.model.Person;
import org.apache.struts.register.util.HibernateUtils;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import java.util.List;

public class list extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private List<Person> list;

    @Override
    public String execute() {

        Session session = HibernateUtils.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            // 方式一：使用HQL语句
            list = session.createQuery("FROM Person").list(); // 使用HQL查询
            tx.commit();
            return SUCCESS;
        } catch (RuntimeException e) {
            tx.rollback();
            throw e;

        } finally {
            session.close();
        }

    }

    public List<Person> getList() {
        return list;
    }
}
